public class test2 {
    //力扣 931.最小路径和
    public int minFallingPathSum(int[][] matrix) {
        //创建dp表
        //初始化
        //填表
        //返回值

        int m = matrix.length,n = matrix[0].length;
        int[][] dp = new int[m+1][n+2];
        for(int j = 1;j<m+1;j++){
            dp[j][0] = dp[j][n+1] = Integer.MAX_VALUE;
        }

        for(int i = 1;i<m+1;i++){
            for(int j = 1;j<n+1;j++){
                int tmp = Math.min(dp[i-1][j-1],dp[i-1][j]);
                dp[i][j] = Math.min(tmp,dp[i-1][j+1])+matrix[i-1][j-1];
            }
        }
        int min = Integer.MAX_VALUE;
        for(int j = 1;j<n+1;j++){
            min = dp[m][j]<min?dp[m][j]:min;
        }
        return min;
    }
}
